| Total Complexity | 2 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 8 | |||
| 9 | @CommandHandler(CreateShootingCommand) |
||
| 10 | export class CreateShootingCommandHandler { |
||
| 11 | constructor( |
||
| 12 | @Inject('ISchoolRepository') |
||
| 13 | private readonly schoolRepository: ISchoolRepository, |
||
| 14 | @Inject('IShootingRepository') |
||
| 15 | private readonly shootingRepository: IShootingRepository, |
||
| 16 | ) {} |
||
| 17 | |||
| 18 | public async execute(command: CreateShootingCommand): Promise<string> { |
||
| 19 | const { name, groupClosingDate, individualClosingDate, schoolId, shootingDate, notice } = command; |
||
| 20 | |||
| 21 | const school = await this.schoolRepository.findOneById(schoolId); |
||
| 22 | if (!school) { |
||
| 23 | throw new SchoolNotFoundException(); |
||
| 24 | } |
||
| 25 | |||
| 26 | const shooting = await this.shootingRepository.save( |
||
| 27 | new Shooting( |
||
| 28 | name, |
||
| 29 | shootingDate, |
||
| 30 | groupClosingDate, |
||
| 31 | individualClosingDate, |
||
| 32 | ShootingStatus.DISABLED, |
||
| 33 | school, |
||
| 34 | notice |
||
| 35 | ) |
||
| 36 | ); |
||
| 37 | |||
| 38 | return shooting.getId(); |
||
| 39 | } |
||
| 41 |